const staticData = {
    "code": 200,
    "msg": "操作成功",
    "time": "20241225151657",
    "respCode": "200",
    "data": {
        "subId": "503",
        "crossInfo": [{
            "crossId": "501",
            "crossName": "501",
            "fStartPno": 2,
            "fEndPno": 3,
            "rStartPno": 2,
            "rEndPno": 3
        }, {
            "crossId": "502",
            "crossName": "502",
            "fStartPno": 2,
            "fEndPno": 3,
            "rStartPno": 2,
            "rEndPno": 3
        }, {
            "crossId": "503",
            "crossName": "503",
            "fStartPno": 2,
            "fEndPno": 3,
            "rStartPno": 2,
            "rEndPno": 3,
            "master": 2
        }, {
            "crossId": "504",
            "crossName": "504",
            "fStartPno": 2,
            "fEndPno": 3,
            "rStartPno": 2,
            "rEndPno": 3
        }, {
            "crossId": "505",
            "crossName": "505",
            "fStartPno": 2,
            "fEndPno": 3,
            "rStartPno": 2,
            "rEndPno": 3
        }
        ],
        "forward": {
            "lens": [100, 100, 100, 100],
            "speed": [60, 60, 60, 60]
        },
        "reverse": {
            "lens": [100, 100, 100, 100],
            "speed": [60, 60, 60, 60]
        }
    },
    "success": true
}

const mockData = [{
    "siteId": "501",
    "pno": 1,
    "time": 20
}, {
    "siteId": "502",
    "pno": 2,
    "time": 22
}, {
    "siteId": "503",
    "pno": 2,
    "time": 30
}, {
    "siteId": "504",
    "pno": 1,
    "time": 10
}, {
    "siteId": "505",
    "pno": 2,
    "time": 21
}, {
    "siteId": "506",
    "pno": 2,
    "time": 15
}
]

const stageNumber = {
    1: {start: 0, end: 0, key: 1},
    2: {start: 0, end: 0, key: 2},
    3: {start: 0, end: 0, key: 3},
    4: {start: 0, end: 0, key: 4},
    5: {start: 0, end: 0, key: 5},
    6: {start: 0, end: 0, key: 6},
    7: {start: 0, end: 0, key: 7}
}

const stageCrossNumber = {}

const initStageNumber = () => {
    mockData.forEach((item) => {
        stageCrossNumber[item.siteId] = JSON.parse(JSON.stringify(stageNumber))
    })    
}

let oldMsg = {}

// 模拟数据更新
const updateMockData = (time, resData) => {    
    // oldMsg = JSON.parse(JSON.stringify(mockData))
    resData.forEach((item, index) => {
        if (item.time >= 30 + item.pno * 2) {
            item.time = 0
            if (item.pno >= 7) {
                item.pno = 1
            }
            else {
                item.pno += 1
            }
        }
        else {
            item.time += 1
        }
        // 旧数据的pno与原有的不一致，那么表示更新了阶段
        if(!item[index] || !item[index].pno || oldMsg[index].pno !== item.pno) {
            stageCrossNumber[item.siteId][item.pno].start = time
        }
        stageCrossNumber[item.siteId][item.pno].end = time
        
    });
    // console.log('stageCrossNumber', stageCrossNumber['501'][1]);
    // console.log('stageCrossNumber', stageCrossNumber['501'][2]);
    
}
